//
//  NotepadTabBarVC.m
//  NotepadApp
//
//  Created by yobet on 2018/4/12.
//  Copyright © 2018年 HJ. All rights reserved.
//

#import "NotepadTabBarVC.h"
#import "CustomTabBar.h"
#import "HomeVC.h"
#import "SettingVC.h"
#import "KeepVC.h"
#import "SpeedingVC.h"

@interface NotepadTabBarVC ()
@property (nonatomic, strong) CustomTabBar *MtabBar;
@end

@implementation NotepadTabBarVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [UITabBar appearance].translucent = NO;
    //移除顶部线条
    self.tabBar.backgroundImage = [UIImage new];
    self.tabBar.shadowImage = [UIImage new];
    
    _MtabBar = [[CustomTabBar alloc] initWithFrame:self.tabBar.frame];
    _MtabBar.tintColor = [UIColor colorWithRed:27.0/255.0 green:118.0/255.0 blue:208/255.0 alpha:1];
    [_MtabBar.addBtn addTarget:self action:@selector(addBtnClick) forControlEvents:UIControlEventTouchUpInside];
    //设置tabbar时只能用keyValue方式
    [self setValue:_MtabBar forKeyPath:@"tabBar"];
    
    [self setControllers];
    
    self.tabBar.tintColor=HJColor(26, 69, 76);
}
- (void)addBtnClick {
    self.selectedIndex = 1;//关联中间按钮
    UIAlertController * alertController =[UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction * ChargeAction =[UIAlertAction actionWithTitle:@"记账" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NotepadNavVC * nav =[[NotepadNavVC alloc]initWithRootViewController:[[SpeedingVC alloc]init]];
        [self presentViewController:nav animated:YES completion:nil];
    }];
    UIAlertAction *KeepAction =[UIAlertAction actionWithTitle:@"记事" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NotepadNavVC * nav =[[NotepadNavVC alloc]initWithRootViewController:[[KeepVC alloc]init]];
        
        [self presentViewController:nav animated:YES completion:nil];
    }];
    UIAlertAction *cancelAction =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alertController addAction:ChargeAction];
    [alertController addAction:KeepAction];
    [alertController addAction:cancelAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
    
}

- (void)setControllers{

    NotepadNavVC * nav1 =[self addChildViewController:[HomeVC new] title:@"首页" image:@"MO1" selecteImage:@"MO"];
//    NotepadNavVC * nav2 =[self addChildViewController:[AddViewController new] title:@"" image:@"" selecteImage:@""];
    NotepadNavVC * nav3 =[self addChildViewController:[SettingVC new] title:@"设置" image:@"g1" selecteImage:@"g"];
    
    self.viewControllers = [NSArray arrayWithObjects:nav1,nav3, nil];
}

-(NotepadNavVC *)addChildViewController:(UIViewController *)childVC title:(NSString *)title image:(NSString * )image selecteImage:(NSString * )selecteImage {
   
    childVC.tabBarItem.image = [UIImage imageNamed:image];
    childVC.tabBarItem.selectedImage = [UIImage imageNamed:selecteImage];
    childVC.title = title;
    
    NotepadNavVC *nav = [[NotepadNavVC alloc] initWithRootViewController:childVC];
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
    textAttrs[NSFontAttributeName] = HJFontSize(13);
    NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
    selectTextAttrs[NSForegroundColorAttributeName] = HJColor(26, 69, 76);
    selectTextAttrs[NSFontAttributeName] = HJFontSize(13);
    [nav.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [nav.tabBarItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
    
    return nav;
}
@end
